import { describe, expect, it } from "vitest";
import { NumberKind } from "../humanizer-types";
import { PerRangeFormatter } from "./per-range";
import { defaultCurrencyOptions } from "./per-range-default-options";

const defaultDollarTestCases: [number, string][] = [
  // integers
  [999_999_999, "$1.0B"],
  [12_345_789, "$12.3M"],
  [2_345_789, "$2.3M"],
  [999_999, "$1.0M"],
  [345_789, "$345.8k"],
  [45_789, "$45.8k"],
  [5_789, "$5.8k"],
  [999, "$999.00"],
  [789, "$789.00"],
  [89, "$89.00"],
  [9, "$9.00"],
  [0, "$0"],
  [-0, "$0"],
  [-999_999_999, "-$1.0B"],
  [-12_345_789, "-$12.3M"],
  [-2_345_789, "-$2.3M"],
  [-999_999, "-$1.0M"],
  [-345_789, "-$345.8k"],
  [-45_789, "-$45.8k"],
  [-5_789, "-$5.8k"],
  [-999, "-$999.00"],
  [-789, "-$789.00"],
  [-89, "-$89.00"],
  [-9, "-$9.00"],

  // non integers
  [999_999_999.1234686, "$1.0B"],
  [12_345_789.1234686, "$12.3M"],
  [2_345_789.1234686, "$2.3M"],
  [999_999.4397, "$1.0M"],
  [345_789.1234686, "$345.8k"],
  [45_789.1234686, "$45.8k"],
  [5_789.1234686, "$5.8k"],
  [999.999, "$1.0k"],
  [999.995, "$1.0k"],
  [999.994, "$999.99"],
  [999.99, "$999.99"],
  [999.1234686, "$999.12"],
  [789.1234686, "$789.12"],
  [89.1234686, "$89.12"],
  [9.1234686, "$9.12"],
  [0.1234686, "$0.12"],

  [-999_999_999.1234686, "-$1.0B"],
  [-12_345_789.1234686, "-$12.3M"],
  [-2_345_789.1234686, "-$2.3M"],
  [-999_999.4397, "-$1.0M"],
  [-345_789.1234686, "-$345.8k"],
  [-45_789.1234686, "-$45.8k"],
  [-5_789.1234686, "-$5.8k"],
  [-999.999, "-$1.0k"],
  [-999.1234686, "-$999.12"],
  [-789.1234686, "-$789.12"],
  [-89.1234686, "-$89.12"],
  [-9.1234686, "-$9.12"],
  [-0.1234686, "-$0.12"],

  // // infinitesimals
  [0.9, "$0.90"],
  [0.095, "$0.10"],
  [0.0095, "~$.00"],
  [0.001, "~$.00"],
  [0.00095, "~$.00"],
  [0.000999999, "~$.00"],
  [0.00012335234, "~$.00"],
  [0.000_000_999999, "$1.0e-6"],
  [0.000_000_02341253, "$2.3e-8"],
  [0.000_000_000_999999, "$1.0e-9"],

  // padding with insignificant zeros for small nums
  [999.1, "$999.10"],
  [789.1, "$789.10"],
  [89.1, "$89.10"],
  [9.1, "$9.10"],
  [0.1, "$0.10"],
  [-999.1, "-$999.10"],
  [-789.1, "-$789.10"],
  [-89.1, "-$89.10"],
  [-9.1, "-$9.10"],
  [-0.1, "-$0.10"],
];

describe("range formatter, using default options for NumberKind.DOLLAR nums, `.stringFormat()`", () => {
  defaultDollarTestCases.forEach(([input, output]) => {
    it(`returns the correct string in case: ${input}`, () => {
      const formatter = new PerRangeFormatter(
        defaultCurrencyOptions(NumberKind.DOLLAR),
      );
      expect(formatter.stringFormat(input)).toEqual(output);
    });
  });
});
